package com.wjy.thread;

import com.wjy.jdbc.JDBCUtil;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 定义线程变量
 *
 * @author ybxxszl
 * @date 2018年10月7日
 * @description TODO
 */
public class ThreadLocalVar {

    private String author_id;

    private String token;

    private Connection conn;

    public ThreadLocalVar() {
        super();
    }

    public ThreadLocalVar(String author_id, String token) {
        super();
        this.author_id = author_id;
        this.token = token;
    }

    public ThreadLocalVar(Connection conn) {
        super();
        this.conn = conn;
    }

    public ThreadLocalVar(String author_id, String token, Connection conn) {
        super();
        this.author_id = author_id;
        this.token = token;
        this.conn = conn;
    }

    public String getAuthor_id() {
        return author_id;
    }

    public void setAuthor_id(String author_id) {
        this.author_id = author_id;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    /**
     * @return Connection 数据库连接
     * @throws ClassNotFoundException 类找不到异常
     * @throws SQLException           SQL异常
     * @date 2018年10月9日
     * @author ybxxszl
     * @description 获取数据库连接
     */
    public Connection getConn() throws ClassNotFoundException, SQLException {
        // 创建数据库连接
        conn = JDBCUtil.getConnect();
        return conn;
    }

    public void setConn(Connection conn) {
        this.conn = conn;
    }

    @Override
    public String toString() {
        return "ThreadLocalVar [author_id=" + author_id + ", token=" + token + ", conn=" + conn + "]";
    }

}
